list::remove() and list::remove | 您所在的位置:网站首页 › stl list remove › list::remove() and list::remove |
Lists are containers used in C++ to store data in a non contiguous fashion, Normally, Arrays and Vectors are contiguous in nature, therefore the insertion and deletion operations are costlier as compared to the insertion and deletion option in Lists. list::remove()remove() function is used to remove all the values from the list that correspond to the value given as parameter to the functionSyntax : listname.remove(value) Parameters : The value of the element to be removed is passed as the parameter. Result : Removes all the elements of the container equal to the value passed as parameterExamples: Input : list list{1, 2, 3, 4, 5}; list.remove(4); Output : 1, 2, 3, 5 Input : list list{1, 2, 2, 2, 5, 6, 7}; list.remove(2); Output : 1, 5, 6, 7Errors and Exceptions Shows error if the value passed doesn’t match the list type.Shows no exception throw guarantee if the comparison between value and elements of the list feature doesn’t throw any exception.CPP// CPP program to illustrate// Implementation of remove() function#include #include using namespace std; int main(){ list mylist{ 1, 2, 2, 2, 5, 6, 7 }; mylist.remove(2); for (auto it = mylist.begin(); it != mylist.end(); ++it) cout |
CopyRight 2018-2019 实验室设备网 版权所有 |